var oTxt = document.getElementById("code");
var oBtn = document.getElementById("btn1");

function random(min, max) {
	return Math.floor(Math.random() * (max - min + 1) + min);
}

function checkNum() {
	oTxt.innerHTML = ''
	for (var i = 0; i < 6; i++) {
		var code = random(48, 122);
		if (code >= 58 && code <= 64 || code >= 91 && code <= 96) {
			i--;
		} else {
			var span = document.createElement('span')
			span.innerText = String.fromCharCode(code)
			span.style.color = '#' + getColor()
			oTxt.appendChild(span)
		}
	}
	return oTxt;
}
// 获得随机色
function getColor() {
	var chars = ['0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'A', 'B', 'C', 'D', 'E', 'F'];

	function generateMixed(n) {
		var res = "";
		for (var i = 0; i < n; i++) {
			var id = Math.ceil(Math.random() * 16);
			res += chars[id];
		}
		return res;
	}
	return generateMixed(6);
}
window.onload = function () {
	checkNum();
}

oBtn.onclick = function () {
	checkNum();
}